<?php

namespace App\Http\Middleware;

use App\Exceptions\CodeMessageException;
use App\Tools\Func;
use Closure;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Route;

class VerifyToken
{
    use Func;

    public function handle($request, Closure $next, $guard = null)
    {
        $userId = $request->header('token');

        if (!$userId) {
            return $this->returnJson401();
        }
        // $this->setLogInfo('账号'.$user->UserName.'进入路由', $route);
        request()->offsetSet('user_id', $userId);
        return $next($request);
    }
}
